<?php
require_once "jssdk.php";

$数据 = pdo()->selectColumns('public_serv_accounts',array('AppSecret','app_id'),array('id'=>$_SESSION['vo用户数据']['公众号ID']));

$jssdk = new JSSDK($数据['app_id'], $数据['AppSecret']);
$signPackage = $jssdk->getSignPackage();
date_default_timezone_set('Asia/Shanghai');
$c用户 = new C用户($bm->vo信息中心);
global $paramArray;

$state = $_GET['state'];
//某些页面要传多个参数时，需要通过state参数分解
if(substr($state,0,3)=='000'){
    $enc=substr($state,3);
    $paramArray=Tools::object2array(json_decode(urldecode($enc)));
}
$群id = isset($_GET['群id'])?$_GET['群id']:$paramArray['群id'];
$群信息 = $c用户->fc查找群信息($群id);
$_GET['群id'] =($_GET['群id'])?$_GET['群id']:$paramArray['群id'];
$sql1 = "select a.* from 会议表 a LEFT  JOIN 群详情 b on(a.id=b.父id) where b.id=".$群id;

$huiyi_res = pdo()->selectOne($sql1);
$paramArray['meet_id'] = empty($paramArray['meet_id'])?$huiyi_res['id']:$paramArray['meet_id'];
$sql = "select * from 会议表 where id=".$paramArray['meet_id'];
$huiyi_qun_res = pdo()->selectOne($sql);

$paramArray['群id'] = empty($paramArray['群id'])?$paramArray['群id']:$群id;
$back = Tools::url('conference',$huiyi_res['下一步'],$paramArray);


$openId = getCurrentUserOID();
if(empty($openId)) exit('参数错误');
$bm = new CUI数据中心(Page::b病历管理,$openId);
$群聊列表 = $bm->生成有效链接('Seller21QunLiao_List',$_GET['state']);
$群组列表=$bm->生成有效链接('Seller20Qunzu_list',$_GET['state']);

if($群信息['父id'] == 1){
    $群列表 = $群组列表;
}else if($群信息['父id'] == 0){
    $群列表 = $群聊列表;
}

$用户是否是群用户 = $c用户->fc查看用户是否是群用户($群id);
$成员列表 = $bm->生成有效链接('Seller20Qunzu_ChengYuan',$_GET['state']).'&群id='.$群id.'&父id='.$_GET['父id'];
$pinjie = array('群id'=>$群id,'父id'=>$_GET['父id'],'用户id'=>$_SESSION['vo用户数据']['id'],'用户openID'=>$_SESSION['vo用户数据']['openID']);
$群文档 = $bm->生成有效链接("Seller20QunWenDang",$_GET['state'],$pinjie);
$群主题 = $bm->生成有效链接('QunTitle',$_GET['state'],$pinjie);


if(!$用户是否是群用户){
    if($huiyi_qun_res){
        $url = $bm->生成有效链接('websocket_qun_ts',$_GET['state']);
        echo "<script>location.href='".$url."&qun_id=".$群id."'</script>";
    }else{
        echo "<script>alert('您不是群成员或未通过审核');location.replace(location.href='".$群列表."&父id=".$_GET['父id']."');</script>";

    }

}
$用户信息 = pdo()->selectOne("SELECT `头像` FROM `用户` WHERE `id` ='".$_SESSION['vo用户数据']['id']."';");

$time = date("Y-m-d H:i:s",time());

$群成员 = $c用户->fx群成员($_GET['群id'],'已审核');
$群主 = $c用户->fx群成员($_GET['群id'],'群主');
$未审核成员 = $c用户->fx群成员($_GET['群id'],'未审核');

?>
<!DOCTYPE html>
<html>

<head>
	<meta charset='UTF-8' />
	<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> -->
	<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no"/>
<!-- 	<meta name="apple-mobile-web-app-capable" content="yes" /> -->
	<title><?= $群信息['群名称']?></title>
	<link rel="stylesheet" href="../style/common.css?<?=版本?>">
	<link rel="stylesheet" href="http://demo.open.weixin.qq.com/jssdk/css/style.css?ts=1420774989">
	<script src="../js/jquery.js"></script>
	<meta charset='UTF-8' />
	<script src="//res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
	<script src="../resource/js/jquery-1.11.1.min.js"></script>
	<!--<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>--><!--新注释-->
	<script type="text/javascript" src="../js/underscore.js"></script>
	<script type="text/javascript" src="../js/pinchzoom.js"></script>
	<script src="../resource/js/binaryajax.js"></script>
	<script src="../resource/js/exif.js"></script>
	<script src="../resource/js/megapix-image.js"></script>
	<script src="../resource/js/jquery.make-thumb.js"></script>

	
	<script src="../resource/js/jquery-form.js"></script>
	<!-- Include all compiled plugins (below), or include individual files as needed -->
	<script src="../resource/js/bootstrap.min.js"></script>
	<script src="../resource/js/hermes.js"></script>
    <script src="../resource/js/reconnecting-websocket.min.js"></script>
	<!-- 图片放大缩小 -->
	<script type="text/javascript">
		$(function () {
			$('div.pinch-zoom').each(function () {
				new RTP.PinchZoom($(this), {});
			});
		})
	</script>
	<!--二维码弹层--><!--新注释-->
	<!--<style>
		.ewm-edit .ewm-img #show_erweim img{width:160px;height:160px;}
	</style>-->
</head>

<body>
<script language="javascript" type="text/javascript">

	var localId = '';
	var serverId = '';
	var images = {
		localId: [],
		serverId: []
	};

	wx.config({
		debug: false,
		appId: '<?php echo $signPackage["appId"];?>',
		timestamp: <?php echo $signPackage["timestamp"];?>,
		nonceStr: '<?php echo $signPackage["nonceStr"];?>',
		signature: '<?php echo $signPackage["signature"];?>',
		jsApiList: [
			'startRecord',
			'stopRecord',
			'onRecordEnd',
			'playVoice',
			'pauseVoice',
			'stopVoice',
			'uploadVoice',
			'downloadVoice',
			'chooseImage',
			'previewImage',
			'uploadImage',
			'downloadImage',
            'onVoiceRecordEnd'
		]
	});

	wx.ready(function(){
		wx.hideOptionMenu(); //隐藏右上角菜单接口
	});

	$(document).ready(function(){

        var userid = $('#userid').val(); //get user id
        var headpic = $('#headpic').val(); //get user 头像
        var username = $('#username').val(); //get user 头像
        var 课程id = ""; //get 课程id
        var 群id = $('#群id').val(); //get 群id
        var serverId="";//语音
		//create a new WebSocket object.
		var wsUri = "ws://<?= G_websocket接口.":".G_websocket端口."/".G_websocket地址?>/server.php";

		websocket = new ReconnectingWebSocket(wsUri);

		websocket.onopen = function(ev) { // connection is open
			$('#message_box').append("<div class=\"system_msg\"></div>");

            var msg = {
                type: 'login',
                userid: userid,
                headpic: headpic,
                username: username,
                课程id: 课程id,
                群id: 群id,
            };
            //convert and send data to server
            websocket.send(JSON.stringify(msg));
		};

		$('.send-btn').click(function(){ //use clicks message send button
			var mymessage = $('#message').val(); //get message text

			$.post('agent_manages.php?state=<?=$_GET['state']?>',{'群id':'<?= $_GET['群id']?>',"参数":'是否是群成员'},function(date){

				if(date>1){

					if(mymessage == "" || mymessage == null || mymessage == " "){ //emtpy message?
						alert("请输入文字!");
					}
					//prepare json data
					if(mymessage != "" && mymessage!=" " && mymessage!=null){
						//prepare json data
						$.post('agent_manages.php',{'message':mymessage,"userid":userid,"serverId":serverId,'headpic':headpic,"群id":群id,'参数':'群聊'},function(data){
							var 地址="";
							var msg = {
                                type: 'usermsg',
								message: mymessage,
								userid: userid,
								headpic: headpic,
								username: username,
								课程id: 课程id,
								群id: 群id,
								serverId:serverId,
								地址:地址,
							};
							//convert and send data to server
							websocket.send(JSON.stringify(msg));
						});
						$("#message").focus();
						$("#message").attr("autofocus","autofocus");
						$("#message").val("");
						footerfunction();
					}

				}else{
					alert('您已被移除该群!');
					location.replace(location.href='<?=$群列表."&父id=".$_GET['父id']?>');
				}
			});


		});

		//#### Message received from server?

		websocket.onmessage = function(ev) {
			var msg = JSON.parse(ev.data); //PHP sends Json data
			var type = msg.type; //message type
			var uid = msg.userid; //user name
			var upic = msg.headpic; //user name
			var uname = msg.username; //user name
			var u课程id = msg.课程id; //user name
			var u群id = msg.群id; //user name
			var userver = msg.serverId; //message text
			var 群id = $('#群id').val();
			var userid = $('#userid').val(); //get user id
			var umsg = msg.message; //message text
			var u地址 = msg.地址; //message text
			if(u群id!=""){
				if(u群id==群id){
					if(type == 'usermsg')
					{
						if(userver!=""){
							if(uid==userid){
								$('#message_box').append('<div class="chat-item-m"> <div class="style2"><div class="chat-item-img"><img  src="'+upic+'"></div></div><div class="chat-item-contr"><span class="font" onclick="bofang(\''+userver+'\')" ><span id="'+userver+'" ok1="0"><img  src="../style/xiaohongdian.gif" alt=""></span ><img style="padding-top:3px;" src="../style/yuyincont2.gif" alt=""></span></div><div class="clear"></div></div>')
							}else{
								$('#message_box').append('<div class="chat-item-o"><div class="style1"><div class="chat-item-img"><img src="'+upic+'"></div></div><div class="chat-item-contl"><div class="name">'+uname+'</div><span class="font" onclick="bofang(\''+userver+'\')"><img src="../style/yuyincont.gif" style="padding-top:3px;" alt=""><span id="'+userver+'" ok1="0"><img  src="../style/xiaohongdian.gif" alt=""></span></span></div><div class="clear"></div></div>')
							}
						}else if(umsg!=""){
							if(uid==userid){
								$('#message_box').append('<div class="chat-item-m"><div class="style2"><div class="chat-item-img"><img src="'+upic+'" ></div></div><div class="chat-item-contr"><span class="font">'+ umsg +'</span></div><div class="clear"></div></div>')
							}else{
								$('#message_box').append('<div class="chat-item-o"><div class="style1"><div class="chat-item-img"><img src="'+upic+'" ></div></div><div class="chat-item-contl"><div class="name">'+uname+'</div><span class="font">'+ umsg +'</span></div><div class="clear"></div></div>')
							}
						}else if(u地址!=""){
							var dizhi="http://<?php echo $_SERVER['HTTP_HOST']?>/Ram_disk/img/"+u地址;
							if(uid==userid){
//								$('#message_box').append('<div>'+dizhi+'</div><img src="'+dizhi+'" width=300>');
								$('#message_box').append('<div class="chat-item-m" ><div class="style2"><div class="chat-item-img"><img src="'+upic+'" style="overflow:hidden;"></div></div><div class="chat-item-contr" style=""><span class="font"><img src="'+dizhi+'" style="height:100px;" onclick="imgbig(this)"></span></div><div class="clear"></div></div>')
							}else{
								$('#message_box').append('<div class="chat-item-o"><div class="style1"><div class="chat-item-img"><img src="'+upic+'" ></div></div><div class="chat-item-contl"  style=""><div class="name">'+uname+'</div><span class="font"><img src="'+dizhi+'" style="height:100px;" onclick="imgbig(this)"></span></div><div class="clear"></div></div>')
							}
						}

					}
				}

			}
			footerfunction();
			if(type == 'system'&& umsg=='<?=$_SERVER["REMOTE_ADDR"]?>')
			{
				$.post('agent_manages.php',{'用户ip':umsg,"用户id":userid,"群id":群id,'参数':'群成员离线信息'},function(data){

				})
			}
		};

		websocket.onerror	= function(ev){
            //$('#message_box').append("<div class='chat-time'>由于您的网络原因,连接断开,请退出后重新进入.</div>");
        };
	});
	function myClose(){
		websocket.onclose();
	}



</script>

<div class="class_talk_con">
	<!-- header begin-->
	<div class="class_talk_con_header">
		
		<dl>
			<?php if($huiyi_res):?>
				<dd class="return_class_list"><a href='<?=$back?>'></a></dd><!--返回群列表-->
			<?php else: ?>
			<dd class="return_class_list"><a href='<?=$群列表."&父id=".$群信息['父id']?>'></a></dd><!--返回群列表-->
			<?php endif;?>
			<div class="class_talk_con_header_line"></div>
			<dd class="in_class_group"><a href="<?= $成员列表?>&meet_id=<?=$paramArray['会议id']?>"></a></dd><!--进入群成员-->
            <?php if($群信息['群名称'] == '循环专业委员会'){ ?>
			<dd class="in_class_document"><a href='<?=$群文档?>'></a></dd>
			<div class="class_talk_con_header_line1"></div>
            <?php }?>
			<dd class="in_class_view"><a href="<?=$群主题?>"></a></dd><!--进入群主题-->
		</dl>
		<div class="class_talk_con_header_history" style="display:none;"><div> 查看历史消息</div><input type="button" id="查询起始值" name="查询起始值" onclick="查看历史()"  value="1" /></div>
	</div>
	<!-- header end-->

	<div class="class_talk_con_view">
		<!--聊天部分 begin-->
		<div id="chat">
			<div id="big-chat">
				<div class="content myContent" id="message_box" style="padding-bottom:88px; padding-top:88px;"></div>
			</div>
		</div>
		<!--聊天部分 end-->


		<!--文本框发送部分 begin-->
		<div style="display:none;" class="txtsendbg" onclick="closetxtsend1()" id="txtsendbg"></div>
		<div style=" display:none;" class="txtsendcontent" id="txtsendcontent">
			<div class="txt_pos">
				<div class="txt_pos_header">
					<div class="txt_pos_header_cancel" onclick="closetxtsend()">取消</div>
					<div class="send-btn" onclick="sendover()">发送</div>
				</div>
				<div class="txt_pos_input">
					<!--<div class="txt_post_bg" onclick="document.getElementById('qq').style.display='none'"></div>-->
					<input type="hidden" name="userid" id="userid" value="<?=$_SESSION['vo用户数据']['id'];?>" />
					<input type="hidden" name="username" id="username" value="<?=$_SESSION['vo用户数据']['name'];?>" />
					<input type="hidden" name="headpic"id="headpic" value="<?=$用户信息['头像']?>"/>
					<input type="hidden" name="群id"  id="群id" value="<?=$群id?>"/>
					<!-- <input type="text" name="message" id="message" onfocus="messfacus()" onblur="messblur()"/></div> -->
					<textarea name="message" cols="" rows="" id="message"  autofocus="autofocus" onblur="blurover()"></textarea>
				</div>
			</div>
		</div>

		<!--文本框发送部分 end-->
		<!--图片上传部分 begin-->
		<iframe name="ifr" style="display: none;"></iframe>
		<form  id="formtu" target="ifr" enctype="multipart/form-data" style="display: none" >
			<input type="file" name="pic" id="doc"/>
		</form>
		<div id="imgbbig" style="display:none; width:100%; height:100%; position:fixed; left:0; top:0; background-color:#FFF; z-index:9999; ">
			<div class="pinch-zoom" style="position:relative;vertical-align:middle;text-align:center;">
				<img src="../style/chat001.png" onclick="imgbigclose()" style="margin:auto;padding-bottom:500px;" />
			</div>
		</div>
		<!--图片上传部分 end-->
		<!--录音部分 begin-->
		<div class="time-bg"><div class="time">60s</div></div>
		<!--录音部分 end-->


		<div class="class_talk_con_footer">
			<table id="class_talk_con_footer_frame">
				<tr>
					<td class="w44pl"><div class="class_talk_con_footer_icon_image" onclick="uploadimg()"></div></td>
					<td class="m_show"><div class="class_talk_con_footer_icon_audio" onClick="qwertyui()"></div></td>
					<td class="m_hide" style="display:none; ">
						<div class="class_talk_con_footer_icon_audio_on" onclick="xianshi(1,60)">开始录音</div><!--开始录音-->
						<div class="class_talk_con_footer_icon_audio_off" style="display: none" onclick="xianshi(2,59)">发送</div><!--结束录音-->
					</td>
					<td class="w44pr"><div class="class_talk_con_footer_icon_txt" onclick="funtxtsend();"></div><div style="display:none;" class="closeabs"  onClick="chatyl()"></div></td>

				</tr>
			</table>
		</div>
	</div>
</div>

<div id="chat"></div>
	<!-- 点击图片放大、收缩插件 -->



</body>
</html>

<script language="JavaScript">
	function closeWinds(){
		if(typeof(WeixinJSBridge)=='undefined'){
			window.close();
		}else

			WeixinJSBridge.invoke('closeWindow',{},function(res){

				//alert(res.err_msg);
				return true;
			});
	}

</script >

<script language="JavaScript">
	查看历史();
	function syncUpload(localIds){

		var localId = localIds.pop();

		wx.uploadImage({
			localId: localId,
			isShowProgressTips: 1,
			success: function (res) {
				var imageId = res.serverId; // 返回图片的服务器端ID
				var userid = $('#userid').val(); //get user id
				var headpic = $('#headpic').val(); //get user 头像
				var username = $('#username').val(); //get user 头像
				var 课程id = ""; //get 课程id
				var 群id = $('#群id').val(); //get 群id

				$.post('agent_manages.php',{'imageId':imageId,"userid":userid,"群id":群id,'参数':'群聊'},function(data){

					var serverId="";//语音
					var message="";//语音
					var msg = {
                        type: 'usermsg',
						serverId: serverId,
						userid: userid,
						message: message,
						headpic: headpic,
						username: username,
						课程id: 课程id,
						群id:群id,
						地址:data,
					};
					websocket.send(JSON.stringify(msg));

				})

			}
		});
	};
	function uploadimg(){

		wx.chooseImage({
			count: 1, // 默认9
			sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
			sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
			success: function (res) {
				localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片

				syncUpload(localIds);

			}

		});
	}



    function 查看历史(){
        var page = $('#查询起始值').val();
        $.ajax({
            url:"agent_manages.php",
            type:'post',
            async:false,
            data:{参数:'查看群历史消息',page:page,群id:'<?=$_GET['群id']?>',时间:'<?=$time?>'},
            datatype:'json',
            success:function(data){
                json = eval(data);

                str ='';

                var 前一时间 ='2016/01/01 00:00:00';

                for(var i=0; i<json.length; i++) {
                    if(i>0) 前一时间 = json[i-1].时间;
                    前一时间2=  前一时间.replace(/\-/g, "/") ;
                    当前时间2 = json[i].时间.replace(/\-/g, "/") ;


                    var t1=new Date(前一时间2);
                    var t2=new Date(当前时间2);
                    var s=(t2.getTime()-t1.getTime());//毫秒
                    s=(s/(1000*60));
                    if(s>1) str+="<div class='chat-time'>"+当前时间2+"</div>";

                    if(json[i].result2){
                        str+='<p>'+json[i].result2+'</p>';
                        $('#show123').remove();
                        $('#查询起始值').remove();
                        $(".class_talk_con_header_history").remove();
                    }
                    var 图像="../cache/card_img/top_index.jpg";
                    if(json[i].头像 !='') 图像 = json[i].头像;
                    var 本用户 ='<?=$_SESSION['vo用户数据']['id']?>';

                    if(json[i].聊天类型=='语音'){

               if( 本用户 == json[i].用户id){
               str+='  <div class="chat-item-m" style=""><div class="style2"><div class="chat-item-img"><img style="width:40px;padding-top:3px;height:40px;border-radius: 20px;" src="'+图像+'"  ></div></div><div class="chat-item-contr"><span class="font" > <span><img onclick="playaudio(\''+json[i].serverid+'\')" style="padding-top:3px;" src="style/yuyincont2.gif" alt=""> <audio  status="0" id="'+json[i].serverid+'" src="http://<?php echo $_SERVER['HTTP_HOST']?>/Ram_disk/'+json[i].serverid+'.mp3" ></audio></span></span> </div><div class="clear"></div></div>';
               }else{
               str+=' <div class="chat-item-o" style=""><div class="style1"><div class="chat-item-img"><img class="abc" style="width:40px;height:40px;border-radius: 20px;" src="'+图像+'" style="padding-top:3px;"></div></div><div class="chat-item-contl"><div class="name">'+json[i].name+'</div><span class="font"> <img onclick="playaudio(\''+json[i].serverid+'\')" src="style/yuyincont.gif" style="padding-top:3px;" alt=""><span><audio   status="0" id="'+json[i].serverid+'" src="http://<?php echo $_SERVER['HTTP_HOST']?>/Ram_disk/'+json[i].serverid+'.mp3" ></audio></span> </span> </div><div class="clear"></div></div>';
               }
               
               }
               else if(json[i].聊天类型=='文本'){
               if( 本用户 == json[i].用户id){
               str+='  <div class="chat-item-m" style=""><div class="style2"><div class="chat-item-img"><img  style="width:40px;height:40px;border-radius: 20px;" src="'+图像+'" ></div></div><div class="chat-item-contr"><span class="font font-right">'+json[i].聊天内容+'</span></div><div class="clear"></div></div>';
               }else{
               str+='  <div class="chat-item-o" style=""><div class="style1"><div class="chat-item-img"><img   style="width:40px;height:40px;border-radius: 20px;" src="'+图像+'"></div></div><div class="chat-item-contl"><div class="name">'+json[i].name+'</div><span class="font font-left">'+json[i].聊天内容+'</span></div><div class="clear"></div></div>';
               }
               }
               else if(json[i].聊天类型=='图片'){
               if( 本用户 == json[i].用户id){
               str+='  <div class="chat-item-m" style=""><div class="style2"><div class="chat-item-img"><img  style="width:40px;height:40px;border-radius:20px;" src="'+图像+'" ></div></div><div class="chat-item-contr"><span class="font font-right"><img src="http://<?php echo $_SERVER['HTTP_HOST']?>/Ram_disk/img/'+json[i].地址+'"style="height:100px;" onclick="imgbig(this)"/></span></div><div class="clear"></div></div>';
               }else{
               str+='  <div class="chat-item-o" style=""><div class="style1"><div class="chat-item-img"><img   style="width:40px;height:40px;border-radius:20px;" src="'+图像+'"></div></div><div class="chat-item-contl"><div class="name">'+json[i].name+'</div><span class="font font-left"><img src="http://<?php echo $_SERVER['HTTP_HOST']?>/Ram_disk/img/'+json[i].地址+'"style="height:100px;" onclick="imgbig(this)"/></span></div><div class="clear"></div></div>';
               }
                    }
                }

                $(str).prependTo("#message_box");

                if($(str)){
                    $(".class_talk_con_header_history").show();
                }
                $('#查询起始值').val(page*1 + 1);
                // alert(data);
            }
        })
        // $.post('agent_manages.php',{'page':page,"群id":'<?=$_GET['群id']?>',"时间":'<?=$time?>','参数':'查看群历史消息'},function(data){


        // });

    }

    function uploadimgclose(){
        $(".uploadimg11").hide();
    }
    function fun11111(num3){
        if(num3==1){
            $("footer .input-btn12").children().attr("src","style/jianpan.gif");
            $(".wenzi").hide().next().show();
        }else
        {
            $(".yuyin").hide().prev().show();
            $("footer .input-btn11").children().attr("src","style/shuohua.gif");
        }
    }


    function startluyin(){
        wx.startRecord({
            cancel: function () {
                alert('用户拒绝授权录音');
            }
        });
    }

    function send_record(res){
        localId = res.localId;
        wx.uploadVoice({
            localId: localId,
            success: function (res) {
                //alert('上传语音成功，serverId 为' + res.serverId);
                serverId = res.serverId;
                var userid = $('#userid').val(); //get user id
                var headpic = $('#headpic').val(); //get user 头像
                var username = $('#username').val(); //get user 头像
                var 群id = $('#群id').val(); //get 课程id
                var 课程id = ""; //get 课程id
                var 地址 = ""; //get 课程id
                var message = ""; //get 课程id
                $.post('agent_manages.php',{'serverId':serverId,'message':message,"userid":userid,'headpic':headpic,"群id":群id,'参数':'群聊'},function(data){

                    var msg = {
                        type: 'usermsg',
                        serverId: serverId,
                        userid: userid,
                        message: message,
                        headpic: headpic,
                        username: username,
                        课程id: 课程id,
                        群id:群id,
                        地址:地址,
                    };
                    websocket.send(JSON.stringify(msg));

                });
            }
        });
    }

    function stopluyin(){
        wx.stopRecord({
            success: function (res) {
                send_record(res);
            },
            fail: function (res) {
                alert(JSON.stringify(res));
            }
        });
    }
    function auto_stop(){
        wx.onVoiceRecordEnd({
            // 录音时间超过一分钟没有停止的时候会执行 complete 回调
            complete: function (res) {
                send_record(res);
                chatyl();
            }
        });

    }
    function stopluyin1(){
        wx.stopRecord({
            success: function (res) {
                localId = res.localId;

            },
            fail: function (res) {
                alert(JSON.stringify(res));
            }
        });
    }
    function bofang(serverId){
        //	alert(serverId);
        if (serverId == '') {
            alert('请先使用 uploadVoice 上传声音');
            return;
        }
        hidens(serverId);
        wx.downloadVoice({
            serverId: serverId,
            success: function (res) {
                //alert('下载语音成功，localId 为' + res.localId);
                 localId = res.localId;
                if($("#"+serverId).attr("ok1")==0){
                	wx.playVoice({
                	    localId: localId
                	});
                	$("#"+serverId).attr("ok1",1);
                }else{
                	wx.pauseVoice({
                	    localId: localId
                	});
                	$("#"+serverId).attr("ok1",0);
                }
               
               
            }
        });
    }

       function xianshi(num2,num){
        if(num2==1){
            $(".time-bg").show();
            $(".class_talk_con_footer_icon_audio_off").show();
            $(".class_talk_con_footer_icon_audio_on").hide();
            $(".floorbg").show();
            startluyin();
            setTimeout(show123(num),1000);
            auto_stop();
            $(".class_talk_con_footer_icon_audio_on").attr("luyin",1);
        }else
        {
            $(".time-bg").hide();
            $(".class_talk_con_footer_icon_audio_on").show();
            $(".class_talk_con_footer_icon_audio_off").hide();
            $(".floorbg").hide();
            clearTimeout(dingshi);
            stopluyin();
             $(".class_talk_con_footer_icon_audio_on").attr("luyin",0);
            footerfunction();
            $("#class_talk_con_footer_frame").removeClass("audio_xx");
            $(".m_show").show();
            $(".m_hide").hide();
            $(".closeabs").hide();
        }
    }

    function qungroup(){
        $("#qun-group-bg").show();
        $("#qun-group").show();
    }
    function qungrouphide(){
        $("#qun-group-bg").hide();
        $("#qun-group").hide();
    }

 function show123(变量) {
        $(".time").text(变量+"s");
        var now=变量-1;
        if (parseInt(变量) ==0) {
           xianshi(2,59);
        }else if(parseInt(变量) >0){
            dingshi=setTimeout(function () {
                show123(now);
            }, 1000);
        }

    }
    function hidens(num){
        $('#'+num).hide();
    }

    function imgbig(obj){
        $("#imgbbig").show();
        var img=$(obj).attr('src');
        $(".pinch-zoom").find("img").attr("src",img);
    }

    function imgbigclose(){
        $("#imgbbig").hide();
    }



</script>
<script type="text/javascript">


    function 显示二维码(){

        $.post('agent_manages.php?state=<?=$_GET['state']?>',{'群id':'<?= $_GET['群id']?>',"参数":'生成群二维码'},function(data){

            if(data){
                $('#show_ewm').show();
                var  显示 ='<img  src="../cache/wxqrcode/'+data+'.jpg" alt="">';
                $('#show_erweim').html(显示);

            }else {
                alert("显示失败!");
            }

        });
    }

    function playaudio($voiceid){
	if($("#"+$voiceid)[0].paused){
		$("#"+$voiceid)[0].play();
		
	}else{
		$("#"+$voiceid)[0].pause();
	}
    }



</script>
<script>



    // 进入直接到最底部
    window.onload = function(){
        footerfunction();

    }
    function sendover(){
        $("#qq").hide();
        $(".txtsendbg").hide();
        $(".txtsendcontent").hide();
        footerfunction();
    }
    function footerfunction(){
        e1=document.getElementById("big-chat");
        h=e1.scrollHeight;
        document.documentElement.scrollTop=h;
        window.pageYOffset =h;
        document.body.scrollTop=h;
    }



    function qwertyui(){
        $("#class_talk_con_footer_frame").addClass("audio_xx");
        $(".m_hide").show();
        $(".m_show").hide();
        $(".closeabs").show();

    }

    function chatyl(){
        $(".closeabs").hide();
        $("#class_talk_con_footer_frame").removeClass("audio_xx");
        $(".m_show").show();
        $(".m_hide").hide();
        if(!$(".class_talk_con_footer_icon_audio_on").attr("luyin")){
        	stopluyin1();
        }
        $(".time-bg").hide();
        $(".class_talk_con_footer_icon_audio_on").show();
        $(".class_talk_con_footer_icon_audio_off").hide();
        clearTimeout(dingshi)
    }

    function closetxtsend(){
        $(".txtsendbg").hide();
        $(".txtsendcontent").hide();
        footerfunction();
    }

    function funtxtsend(){
        $(".txtsendbg").show(function(){
            $("#message").focus();

        });
        $(".txtsendcontent").show();

    }


    $(".class_talk_con_footer_icon_txt")[0].addEventListener('click',function(ev){
        $("#message")[0].focus()
    })

    function closetxtsend1(){
        $(".txtsendbg").hide();
        $(".txtsendcontent").hide();
        footerfunction();
    }
    //2016-4-12 zhaohui 修改（ios输入法完成返回）
    function blurover(){
        $(".txtsendbg").delay(300).hide(1);
        $(".txtsendcontent").delay(300).hide(1);
        footerfunction();
    }

    // $(function(){
    //     $('.font').click(function(){
    //         $(this).select();
    //         alert(1)
    //     });
    // });
</script>

